/*package com.amigo.online.provider.adv.service.impl;


import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.amigo.online.common.base.service.BaseService;
import com.amigo.online.common.core.response.StatusCode;
import com.amigo.online.common.param.dto.video.AdvApplyDto;
import com.amigo.online.common.param.dto.video.AdvSourceCheckDto;
import com.amigo.online.common.param.result.AdvBundleInfo;
import com.amigo.online.common.param.result.VideoInfo;
import com.amigo.online.provider.adv.exception.AdvException;
import com.amigo.online.provider.adv.service.AdvApplyService;
import com.amigo.online.provider.video.mapper.AdvApplyDetailMapper;
import com.amigo.online.provider.video.mapper.AdvApplyMapper;
import com.amigo.online.provider.video.mapper.AdvBundleMapper;
import com.amigo.online.provider.video.mapper.AdvSourceMapper;
import com.amigo.online.provider.video.mapper.VideoMapper;
import com.amigo.online.provider.video.model.entity.AdvBundle;
import com.amigo.online.provider.video.model.entity.AdvSource;
import com.amigo.online.provider.video.model.entity.Video;
import com.amigo.online.provider.video.service.RedisService;
import com.amigo.online.provider.video.util.ConvertUtil;

@Service
@Transactional(rollbackFor = Exception.class)
public class AdvApplyServiceImpl extends BaseService<> implements AdvApplyService {
	
	@Resource
	AdvApplyMapper advApplyMapper;
	@Resource
	AdvApplyDetailMapper advApplyDetailMapper;
	@Resource
	AdvBundleMapper advBundleMapper;
	@Resource
	AdvSourceMapper advSourceMapper;
	@Resource
	VideoMapper videoMapper;
	@Resource
	private RedisService redisService;
	
	*//**
 * 新增广告申请
 * <p>
 * 校验所选区域是否有剩余广告位
 * <p>
 * 获取全部套餐
 *//*
	@Override
	public boolean newAdvApply(VideoInfo videoInfo, AdvApplyDto adv){
		return true;
		try {
			long nowMilliSeconds = System.currentTimeMillis();
	        long nowSeconds = nowMilliSeconds / 1000;
			AdvApply advApply = new AdvApply();
			
			advApply.setUserId(videoInfo.getUserId());
			advApply.setVideoId(videoInfo.getId());
			advApply.setDay(adv.getDay());
			advApply.setUpdatedTime(nowSeconds);
			advApply.setCreatedTime(nowSeconds);
			advApply.setStartTime(adv.getStartTime());
			advApply.setEndTime(adv.getEndTime());
			advApply.setCheckstatus(0);
			advApply.setType(adv.getType());
			List<AdvBundle> advBundleList = advBundleMapper.findBundleByCodeAndArea(adv);
			Integer totalprice = advBundleMapper.calculatePrice(adv);
			advApply.setTotalprice(totalprice);
			advApplyMapper.insert(advApply);
			List<AdvApplyDetail> detailList = new ArrayList<AdvApplyDetail>();
			for(AdvBundle advBundle:advBundleList) {
				AdvApplyDetail advApplyDetail = new AdvApplyDetail();
				advApplyDetail.setAdvApplyId(advApply.getId());
				advApplyDetail.setAdvBundleId(advBundle.getId());
				advApplyDetail.setAreaId(advBundle.getAreaId());
				advApplyDetail.setLeavecount(advBundle.getCount() * adv.getDay());
				advApplyDetail.setCreatedTime(nowSeconds);
				advApplyDetail.setUpdatedTime(nowSeconds);
			}
			if(detailList.size() > 0) {				
				advApplyDetailMapper.insertList(detailList);
			}
			return true;
		}catch(Exception e) {
			videoMapper.deleteByPrimaryKey(videoInfo.getId());
			String video_key = "video_"+videoInfo.getId();
			redisService.remove(video_key);
			throw e;
		}
	}
	
	*//**
 * 校验所选区域是否有剩余广告位
 *//*
	@Override
	public Integer checkSource(AdvSourceCheckDto dto) {
		List<AdvSource> advSourceList = advSourceMapper.checkSource(dto);
		for(AdvSource advSource: advSourceList) {
			if(advSource.getAdvnumber() - advSource.getAdvusednumber() + dto.getCount() <=0 ) {
				throw new AdvException(StatusCode.ADV_APPLY_EXCEPTION);
			}
		}
		Integer totalprice = advBundleMapper.calculatePrice(dto);
		return totalprice;
	}
	
	*//**
 * 获取全部套餐
 *//*
	@Override
	public List<AdvBundleInfo> getBundle() {
		List<AdvBundle> advBundleList = advBundleMapper.getBundle();
		List<AdvBundleInfo> advBundleInfoList = new ArrayList<AdvBundleInfo>();
		advBundleInfoList = ConvertUtil.AdvBundleToAdvBundleInfo(advBundleList);
		return advBundleInfoList;
	}

	@Override
	public List<Object> listFindAdvBySexAndAge(String sex, int age) {		
		return null;//advApplyMapper.listFindAdvBySexAndAge(sex, age);
	}

	@Override
	public List<Object> listFindAdvBySexAndAgeAndArea(String sex, int age, int cityId) {
		return null;// advApplyMapper.listFindAdvBySexAndAgeAndArea(sex, age, cityId);
	}
	
	
}
*/